package com.adjy.pathbuilders.world;

import java.util.List;

import com.adjy.pathbuilders.objects.GameEntityType;
import com.adjy.pathbuilders.scenario.Scenario;

/**
 * Level class holds information for a single Level of the game
 * 
 */
public class Level {

	private int mostCoins;
	private int bestTime;
	private Scenario scenario;
	private LevelCategory category;
	private String levelId;
	private Level previous, next;
	private final List<GameEntityType> selectableObjects;
	
	/*
	 * When the player wins the previous levels.
	 */
	private boolean enabled;
	
	/**
	 * Constructor for Level
	 * 
	 * @param category
	 *            Category
	 * @param levelId
	 *            ID
	 * @param scenario
	 *            Scenario to be used
	 * @param bestTime
	 *            Best Time
	 * @param mostCoins
	 *            The Record of Coins gotten
	  * @param previous
	  * 			The previous level (the one to enable it).
	  * @param next
	  * 			The next level (the one that will be enable after it).
	  */
	public Level(LevelCategory category, String levelId, Scenario scenario,	int bestTime, int mostCoins, 
			List<GameEntityType> selectableObjects, Level previous, Level next) {
		// FIXME add checks
		this.category = category;
		this.levelId = levelId;
		this.scenario = scenario;
		this.setBestTime(bestTime);
		this.setMostCoins(mostCoins);
		this.setPrevious(previous);
		this.setNext(next);
		this.enabled = previous == null;
		this.selectableObjects = selectableObjects;
	}
	
	public Level getPrevious() {
		return previous;
	}
	
	public void setPrevious(Level previous) {
		this.previous = previous;
	}
	
	public void setNext(Level next) {
		this.next = next;
	}
	
	public Level getNext() {
		return next;
	}
	
	public List<GameEntityType> getSelectableObjects() {
		return selectableObjects;
	}
	
	/**
	 * Gets the Record of Coins Gotten on this Level
	 * 
	 * @return int - record of coins
	 */
	public int getMostCoins() {
		return mostCoins;
	}

	/**
	 * Gets the Best Time in seconds on this Level
	 * 
	 * @return int - time in seconds
	 */
	public int getBestTime() {
		return bestTime;
	}

	/**
	 * Gets the Scenario for this Level
	 * 
	 * @return Scenario
	 */
	public Scenario getScenario() {
		return scenario;
	}

	/**
	 * Gets the Category of this Level
	 * 
	 * @return LevelCategory - Category for this Level
	 */
	public LevelCategory getCategory() {
		return category;
	}

	/**
	 * Gets the Level ID
	 * 
	 * @return String - Level ID
	 */
	public String getLevelID() {
		return levelId;
	}

	public void setBestTime(int newBestTime) {
		this.bestTime = newBestTime;
	}

	public void setMostCoins(int newMostCoins) {
		this.mostCoins = newMostCoins;
	}

	public boolean isEnabled() {
		return this.enabled;
	}
	
	public boolean enable() {
		if(this.previous == null || this.previous.isEnabled()){
			this.enabled = true;
		}else{
			System.out.println("not enabled");
		}
		System.out.println(this.levelId + " ---> "+this.enabled);
		return this.enabled;
	}

}
